
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0003
 * @Author : WangRuoyu 
 * @Date : 2023/5/24 10:51
 */

#include "iostream"
#include "vector"

using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        // vector<bool> st(130);
        // 70是试出来的，130比较靠谱，因为最多128个字符
        vector<bool> st(70);
        int res = 0;
        int j = 0;
        for (int i = 0; i < s.size(); ++i) {
            if (!st[s[i]]) {
                st[s[i]] = true;
                res = max(res, i - j + 1);
                continue;
            }
            while (s[j] != s[i]) {
                st[s[j]] = false;
                j++;
            }
            j++;
        }
        return res;
    }
};

int main() {
    Solution sl;
    int res = sl.lengthOfLongestSubstring("abcabcbb");
    printf("%d", res);
    return 0;
}